package com.codemart.lanze.modules.admin;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import com.codemart.lanze.common.base.controller.BaseController;
import com.codemart.lanze.common.util.ShiroUtils;
import com.codemart.lanze.modules.sys.model.Permission;
import com.codemart.lanze.modules.sys.model.User;
import com.codemart.lanze.modules.sys.service.PermissionService;

/**
 * 后台首页
 */
@Controller
public class AdminController extends BaseController {

	private static final String BASE_PATH = "admin/";

	@Resource
	private PermissionService permissionService;

	/**
	 * 后台根目录直接访问
	 *
	 * @return
	 */
	@GetMapping(value = "/admin")
	public String toAdminIndex() {
		return "redirect:/admin/index";
	}

	/**
	 * 首页
	 *
	 * @return
	 */
	@GetMapping(value = "/admin/index")
	public String index(ModelMap modelMap) {
		// 从shiro的session中取user
		User user = ShiroUtils.getUserEntity();

		List<Permission> menuList = permissionService.findMenuListByUserId(user.getId());
		// 通过model传到页面
		modelMap.addAttribute("menuList", menuList);
		log.info("------进入首页-------");
		return BASE_PATH + "index";
	}

	/**
	 * 欢迎页
	 *
	 * @return
	 */
	@GetMapping(value = "/admin/welcome")
	public String welcome() {
		log.info("------进入欢迎页-------");
		return BASE_PATH + "welcome";
	}

	/**
	 * 未授权页面
	 *
	 * @return
	 */
	@GetMapping(value = "/admin/403")
	public String unauthorized() {
		log.info("------没有权限-------");
		return BASE_PATH + "common/403";
	}
}
